//
//  Status.swift
//  weibo
//
//  Created by 上官风雨 on 15/11/14.
//  Copyright © 2015年 上官风雨. All rights reserved.
//

import UIKit

class Status: NSObject {
    //微博创建时间
    var created_at :String?
    //微博来源
    var source : String?
    //微博id
    var id :Int = 0
    //用户具体数据
    var user:User?
    
    //微博信息内容
    var text :String?
    
    //配置视图数组
    var pic_urls : [[String : String]]?
    
    //计算型属性
    var imageURLs: [NSURL]? {
        guard let urls = pic_urls else {
            return nil
        }
        
        var tempArray = [NSURL]()
        for item in urls {
            //相信后端给的urlString 一定能够转换成 url
            let url = NSURL(string: item["thumbnail_pic"]!)
            tempArray.append(url!)
        }
        return tempArray
    }
    //被转发微博的字段
    var retweeted_status :Status?
    
    init(dict:[String : AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            if let dict = value as? [String : AnyObject] {
                
                user = User(dict: dict)
                
            }
            return
        }
        
        if key == "retweeted_status" {
            
            if let dict = value as? [String : AnyObject]{
                
                retweeted_status = Status(dict: dict)
                
            }
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) { }
    
}
